import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.JFrame;
import javax.swing.border.EmptyBorder;

/**
 * @author mahikian
 *
 */
public class VueSaisiePeriodique extends Vue {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField textFieldIssn ; ;
	private JTextField textFieldNomP;
	
	private JButton buttonEnreg;
	private JButton buttonAnnuler;

	
	public VueSaisiePeriodique(Controleur controleur) {
		super(controleur);
		setTitle("Enregistrement d'un periodique\n");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
		setBounds(100, 100, 431, 228);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblIssn = new JLabel("Issn");
		lblIssn.setHorizontalAlignment(SwingConstants.RIGHT);
		lblIssn.setBounds(93, 42, 61, 15);
		contentPane.add(lblIssn);
		
		textFieldIssn = new JTextField();
		textFieldIssn.setBounds(172, 40, 141, 19);
		contentPane.add(textFieldIssn);
		textFieldIssn.setColumns(10);
		
		JLabel lblNomP = new JLabel("Nom Periodique");
		lblNomP.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNomP.setBounds(46, 87, 108, 15);
		contentPane.add(lblNomP);
		
		textFieldNomP = new JTextField();
		textFieldNomP.setBounds(172, 85, 225, 19);
		contentPane.add(textFieldNomP);
		textFieldNomP.setColumns(10);

		buttonEnreg = new JButton("Enregistrer");
		buttonEnreg.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int num = generationNum();				
				String issn = textFieldIssn.getText();
				String NomPeriodique = textFieldNomP.getText();				
				getControleur().nouvPeriodique(num,issn,NomPeriodique);
				}
		});
		buttonEnreg.setBounds(290, 156, 107, 25);
		contentPane.add(buttonEnreg);
		
		buttonAnnuler = new JButton("Annuler");
		buttonAnnuler.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			getControleur().fermerVue(VueSaisiePeriodique.this);}
		});
		buttonAnnuler.setBounds(47, 156, 107, 25);
		contentPane.add(buttonAnnuler);
	}
	private int generationNum(){
		return getControleur().getPeriodiques().size()+1;
	}
}
